<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>行为日志</title>
		<link rel="stylesheet" href="../../component/ui/css/ui.css" />
	</head>
	<body class="pear-container">
    <div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">模块</label>
							<div class="layui-input-inline">
								<input type="text" name="l.log" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">操作人</label>
							<div class="layui-input-inline">
								<input type="text" name="u.username" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md" lay-filter="user-reset" lay-submit>
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="log-table" lay-filter="log-table"></table>
			</div>
		</div>
		</div>
	</body>


	<script type="text/html" id="log-createTime">
	{{layui.util.toDateString(d.addtime*1000, "yyyy-MM-dd HH:mm:ss")}}
	</script>
    <script type="text/html" id="log-leaveTime">
	{{layui.util.toDateString(d.leavetime*1000, "yyyy-MM-dd HH:mm:ss")}}
	</script>
	<script src="../../config/config.js"></script>
	<script src="../../component/layui/layui.js"></script>
	<script src="../../component/ui/ui.js"></script>
	<script>
		layui.use(['table', 'form', 'jquery', 'element'], function() {
			let table = layui.table;
			let form = layui.form;
			let element = layui.element;
            let $ = layui.jquery;

			let MODULE_PATH = "./";

			let cols = [
				[{
						title: '模块',
						field: 'log',
						align: 'center'
					},
					{
						title: '请求方式',
						field: 'method',
						align: 'center'
					},
					{
						title: '接口',
						field: 'url',
						align: 'center'
					},
					{
						title: '浏览器',
						field: 'agent',
						align: 'center'
					},
					{
						title: '查看时间',
						field: 'addtime',
						templet: '#log-createTime',
						align: 'center'
					},
                    {
						title: '离开时间',
						field: 'leavetime',
						templet: '#log-leaveTime',
						align: 'center'
					},
					{
						title: '操作人',
						field: 'username',
						align: 'center'
					}
				]
			]

			table.render({
				elem: '#log-table',
				url: apiUrl + 'logs/view',
				headers: getHeader(),
				parseData: function(res) {
					return {
						"code": res.code, //解析接口状态
						"msg": res.message, //解析提示文本
						"count": res.data.count, //解析数据长度
						"data": res.data.list //解析数据列表
					};
				},
				page: true,
				cols: cols,
				skin: 'line',
				toolbar: '#user-toolbar',
				defaultToolbar: [{
					title: '刷新',
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports']
			});


			form.on('submit(user-query)', function(data) {
					table.reload('log-table', {
						where: {
							param : $('form').serialize()
						},
						page: {
					        curr: 1
					    }
					})
					return false;
				});
				form.on('submit(user-reset)', function(data){
					table.reload('log-table', {
						where: {
							param : ''
						},
						page: {
					        curr: 1
					    }
					});
					return false;
				})

		})
	</script>
</html>
